package nancal.mp.db.mongo.entity.sys

import nancal.mp.db.mongo.*
import nancal.mp.db.mongo.base.MenuDefine
import nancal.mp.db.mongo.base.wx.OpenIdName
import nancal.mp.db.mongo.entity.dev.ProductLine
import nancal.mp.db.mongo.entity.wx.WxAppUser
import nbcp.base.db.IdCodeName
import nbcp.base.db.IdName
import nbcp.base.db.IdNameUrl
import nbcp.base.db.IdUrl
import nbcp.base.db.annotation.Cn
import nbcp.base.db.annotation.DbEntityGroup
import nbcp.base.model.BaseMarkEntity
import nbcp.base.utils.MyUtil
import nbcp.myoql.db.CityCodeName
import nbcp.myoql.db.comm.DbEntityCascadeDefine
import nbcp.myoql.db.comm.DbEntityCascades
import nbcp.myoql.db.comm.RemoveToSysDustbin
import nbcp.myoql.db.comm.VarTable
import org.springframework.data.mongodb.core.mapping.Document
import java.io.Serializable
import java.time.LocalDateTime

//@DbEntityFieldRefs(
//    DbEntityFieldRef("productLine" , ProductLine::class),
//)
@DbEntityCascadeDefine("productLine.id","productLine.name", ProductLine::class)
@Document
@DbEntityGroup("sys")
data class LangResource(
    var productLine: IdCodeName = IdCodeName(),
    var key: String = "",
    var cn: String = "",
    var en: String = "",
    var remark: String = ""
) : BaseMarkEntity()


/**
 * 品牌是平台维护的数据
 */
@Document
@DbEntityGroup("sys")
data class BrandInfo(
    var code: String = "", //树型结构。类似城市代码。
    var name: String = "",
    var english: String = "", //英文
    var pcode: String = "",
    var logo: IdUrl = IdUrl(),   //logo
    var order: Float = 0.0F,    //排序
    var banner: IdUrl = IdUrl() //淘对Banner
) : BaseMarkEntity()


/**
 * 平台分类
 */
@Document
@DbEntityGroup("sys")
data class CategoryInfo(
    var code: String = "", //树型结构。类似城市代码。
    var name: String = "",
    var english: String = "", //英文
    var parents: MutableList<IdCodeName> = mutableListOf(),
    var logo: IdUrl = IdUrl(),   //logo
    var commission: Int = 0,     // 万元提成
    var order: Float = 0.0F,    //排序
    var banner: IdUrl = IdUrl() //淘对Banner
) : BaseMarkEntity()


/**
 * 敏感词
 */
@Document
@DbEntityGroup("sys")
data class SensitiveWord(
    var word: String = "",
    var mask: String = ""
) : BaseMarkEntity()

/**
 * 聊天内容
 */
@Document
@DbEntityGroup("sys")
data class ImContent(
    var product: IdNameUrl = IdNameUrl(),    //讨论的商品
    var orderId: String = "",               //讨论的订单
    var subject: String = "",               //讨论话题。

    var speeker: IdNameUrl = IdNameUrl(),   //发言者
    var content: String = "",               //发言内容
    var images: MutableList<IdUrl> = mutableListOf(),    //聊天内容发送的图片
    var files: MutableList<IdUrl> = mutableListOf(),     //聊天内容发送的文件
    var target: MutableList<IdNameUrl> = mutableListOf(), //目标用户
    var refContent: String = ""
) : BaseMarkEntity()


/**
 * 商圈
 */
data class TradingArea(
    var city: CityCodeName = CityCodeName(),
    var name: String = ""        //商圈名称
) : BaseMarkEntity()


@Document
@RemoveToSysDustbin
@DbEntityGroup("sys")
@DbEntityCascadeDefine("createBy.id", "createBy.name", WxAppUser::class )
data class test(
    var name: String = "",
    var createBy: OpenIdName = OpenIdName()
) : BaseMarkEntity()

/**
 * 集成子系统
 */
@Cn("子系统信息")
@Document
@DbEntityGroup("sys")
data class SubSystemInfo(
    @Cn("名称")
    var name: SubSystemEnum? = null,

    @Cn("页面路径")
    var pageUrl: String = "",
    @Cn("登录接口")
    var loginUrl: String = "",
    @Cn("注册接口")
    var registerUrl: String = "",

    //2020.1.19  add   系统port   全路径读取配置文件拼全
    @Cn("")
    var port: String = "",

    //new add
    @Cn("登录参数")
    var loginParam: String = "loginName=@loginName&password=@password",
    @Cn("登录成功返回status")
    var responseStatus: Int = 0,

    //管理员 账户及密码   注册时使用
    @Cn("管理员用户名")
    var adminName: String = "",
    @Cn("管理员密码")
    var adminPwd: String = "",
    @Cn("管理员token")
    var adminToken: String = ""
) : BaseMarkEntity()


/**
 * 集成子系统
 */
@Cn("子系统用户信息")
@Document
@DbEntityGroup("sys")
data class SubSystemUserInfo(

    @Cn("关联用户表")
    var user: IdName = IdName(),
    @Cn("密码随机字符串")
    var secKey: String = "",
    @Cn("可以登录的系统")
    var authSys: MutableList<IdName> = mutableListOf(),

    @Cn("用户各系统登录信息")
    var authList: MutableList<UserAuthInfo> = mutableListOf()


) : BaseMarkEntity()

data class UserAuthInfo(
    @Cn("系统名称")
    var systemName: SubSystemEnum? = null,

    @Cn("登录用户名")
    var loginName: String = "",

    @Cn("登录密码")
    var password: String = ""
) : Serializable

@Cn("用户消息")
@Document
@DbEntityGroup("sys")
data class UserMessageInfo(

    @Cn("所属系统")
    var system: SassEnum? = null,

    @Cn("关联用户信息")
    var user: IdName = IdName(),
    @Cn("消息类型")
    var type: MessageTypeEnum? = null,
    @Cn("是否已读")
    var read: Boolean = false,

    @Cn("显示内容")
    var content: String = "",
    @Cn("跳转src")
    var src: String = "",
) : BaseMarkEntity()

//microService
@Cn("微服务信息")
@Document
@DbEntityGroup("sys")
data class MicroServiceInfo(

    @Cn("微服务模块名称")
    var name: String = "",

    @Cn("功能简介")
    var remark: String = "",

    @Cn("version")
    var version: String = "",

    @Cn("文档地址")
    var docSrc: String = "",

    @Cn("关联企业信息")
    var corp: IdName = IdName(),

    @Cn("所属业务域")
    var type: DomainEnum? = null,

/*    @Cn("调用关系")
    var relationship : String = "",*/

    @Cn("微服务详情")
    var details: MutableList<MicroDetail> = mutableListOf(),

    ) : BaseMarkEntity()

//单个微服务
class MicroDetail(

    @Cn("微服务名称")
    var name: String = "",

    @Cn("API输入")
    var apiIn: String = "",
    @Cn("API输出")
    var apiOut: String = "",

    @Cn("标签")
    var tag: String = "",
    @Cn("版本")
    var version: String = "",
    @Cn("实例数")
    var count: Int = 0,

    @Cn("代码仓库")
    var repository: String = "",

    @Cn("创建时间")
    var createAt: LocalDateTime = LocalDateTime.now()

)

@Cn("sso应用配置")
@Document
@DbEntityGroup("sys")
data class SsoConfig(

    @Cn("应用名称")
    var name: String = "",

    @Cn("应用秘钥")
    var secrect: String = MyUtil.getRandomWithLength(24),

    @Cn("应用主页")
    var homepageUrl: String = "",

    @Cn("应用Host")
    var host: String = "",

    //应用实际的名称   appId  例如  datalake,mes 等
    @Cn("appId")
    var appId: String = "",


    @Cn("描述")
    var remark: String = "",

    @Cn("所属企业")
    var corp: IdName = IdName(),

    ) : BaseMarkEntity()

// 微服务 返回数据使用
class AuthOnce(
    var logId: String = "",
    var tempToken: String = "",
    var homepageUrl: String = ""
)


@Cn("sso日志")
@Document
@DbEntityGroup("sys")
data class SsoLog(

    @Cn("应用")
    var info: IdName = IdName(),

    //是否执行回调  执行后跳转页面  未执行 loading
    @Cn("回调状态")
    var status: Boolean = false,

    @Cn("临时token")
    var tempToken: String = "",

    @Cn("有效token")
    var realToken: String = "",

    @Cn("错误信息")
    var remark: String = "",

    ) : BaseMarkEntity()


@Cn("v2_单个系统信息")
@Document
@DbEntityGroup("sys")
data class HomeInfo(

    @Cn("应用名称")
    var name: String = "",

    @Cn("描述内容")
    var remark: String = "",

    @Cn("跳转的url")
    var url: String = "",

    @Cn("跳转的fullUrl")
    var fullUrl: String = "",

    @Cn("ico")
    var ico: String = "",

    @Cn("对应的子系统枚举")
    var sysEnum: SubSystemEnum? = null,

    @Cn("属于的中台分类")
    var type: Platform? = null,

    @Cn("标记")
    var flag: Boolean = false,

    @Cn("排序")
    var sort: Int = 0

) : BaseMarkEntity()


@Cn("Email配置")
@Document
@DbEntityGroup("sys")
data class SysEmailInfo(

    @Cn("邮件标题")
    var title: String = "",

    @Cn("邮件内容")
    var content: String = "",

    @Cn("邮件接受者")
    var users: List<String> = mutableListOf(),

    ) : BaseMarkEntity()


@Cn("菜单")
@Document
@DbEntityGroup("sys")
@VarTable("appId")
open class AppMenu(
    @Cn("英文名称")
    var enName:String = "",
    @Cn("创建时间")
    var createAt: LocalDateTime = LocalDateTime.now(),
    @Cn("更新时间")
    var updateAt: LocalDateTime? = null,
) : MenuDefine()
